Skip to content

Conversation

@ericleib
Copy link

This Pull Request adds support for the shorthand property notation.

This allows to simplify an expression from:

{
  "a": a
}

to:

{
  a
}

This also works for variables:

(
  $foo:= 42;
  {$foo}
)

output:

{
  "foo": 42
}

@mattbaileyuk
Copy link
Member

I believe it's quite a Javascript-y syntax concept, but one I do find convenient, and the implementation is not tied to Javascript, so I've got nothing against including this 🙂

Thoughts, @andrew-coleman?

Copy link
Contributor

@Turings98apprentice Turings98apprentice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this idea! I think there's a small bug that needs fixing still.

I'm a daily user of jsonata, so while this is my first contribution/review for this repo, I have a decent idea of what quirks to look out for.

The short of it is that I created a test scenario that doesn't work as I'd expect:

{
    "expr": "{and, in, or, `true`, `false`, `null`, function, λ}",
    "data": {
        "and": "Logical AND operator",
        "in": "Membership operator",
        "or": "Logical OR operator",
        "true": "Boolean true literal",
        "false": "Boolean false literal",
        "null": "Null literal",
        "function": "Function keyword",
        "λ": "Cooler function keyword"
    },
    "bindings": {},
    "result": {
        "and": "Logical AND operator", <-- Fail
        "in": "Membership operator", <-- Fail
        "or": "Logical OR operator", <-- Fail
        "true": "Boolean true literal", <-- Fail
        "false": "Boolean false literal", <-- Fail
        "null": "Null literal", <-- Fail
        "function": "Function keyword",
        "λ": "Cooler function keyword"
    }
}

Only the lambda function keywords are able to use this shorthand. (See /test/test-suite/groups/boolean-expresssions for similar examples using keywords).

I created a few more tests that seemed useful. I've attached them to this review (I don't know how to work off your branch, so this seemed like the next best option).

If you can get it to pass all these tests, I think it's good to go. I tried hard to break it, and only the keywords method was successful!

case006.json
case007.json
case008.json
case009.json
case010.json
case011.json <- This one fails!
case012.json
case013.json
case014.json
case015.json
keywords.json

I would try to write up a solution for this myself, but I honestly wouldn't know where to start. This was fun to test, and I hope to see this feature in a future release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants